﻿Public Class Shop

    Dim vChosen As Integer
    Dim vFoodPrice As Integer

    Dim vServantPrice As Integer

    Public Property ServantPrice() As Integer
        Get
            Return vServantPrice
        End Get
        Set(ByVal value As Integer)
            vServantPrice = value
            lblServantPrice.Text = "$" & value
        End Set
    End Property

    Public Property Chosen() As Integer
        Get
            Return vChosen
        End Get
        Set(ByVal value As Integer)
            vChosen = value
        End Set
    End Property

    Public Property FoodPrice() As Integer
        Get
            Return vFoodPrice
        End Get
        Set(ByVal value As Integer)
            vFoodPrice = value
        End Set
    End Property

    Private Sub Shop_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ServantPrice = 10

        Dim pts As Integer '= Parent.Controls.OfType(Of StatusPoints).ElementAtOrDefault(0).Points

        pts = 0

        'FoodPrice1.Visible = True

        'If (pts > 500) Then FoodPrice2.Visible = True
        'If (pts > 1000) Then FoodPrice3.Visible = True

    End Sub

    Public Sub NotEnough()
        MsgBox("Not Enough Money", MsgBoxStyle.Critical, "Information")
    End Sub

    Public Sub SetDefaultLoad()
        FoodShop1.Chosen = True
        Chosen = 0
        FoodPrice = FoodShop1.GetPrice
    End Sub

    Public Sub UnlockFood(ByVal value As Integer)
        Select Case value
            Case 0
                FoodShop2.Status = True
            Case 1
                FoodShop3.Status = True
        End Select
    End Sub

    Private Sub FoodShop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FoodShop1.Click, FoodShop2.Click, FoodShop3.Click

        FoodPrice = sender.GetPrice

        If (CheckMoney(FoodPrice) = True) Then

            If (sender.Status = True) Then

                If (FoodShop1.Chosen = True) Then FoodShop1.Chosen = False
                If (FoodShop2.Chosen = True) Then FoodShop2.Chosen = False
                If (FoodShop3.Chosen = True) Then FoodShop3.Chosen = False

                sender.Chosen = True

                Chosen = sender.Type

                FoodPrice = sender.GetPrice
            End If

        Else
            NotEnough()
        End If

    End Sub

    Private Sub ServantShop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ServantShop.Click

        If (CheckMoney(ServantPrice) = True) Then

            Dim milker As New Servant
            Dim amount As Integer = CountServant()

            If (amount < 6) Then

                With milker
                    .Left = 190 + (amount * milker.Width)
                    .Top = 500
                End With

                Parent.Controls.Add(milker)
                Parent.Controls.OfType(Of StatusPoints).ElementAtOrDefault(0).DecreaseMoney(ServantPrice)
            Else
                MsgBox("Max servant reached !", MsgBoxStyle.Critical, "Information")
            End If
        End If
    End Sub

    Private Function CountServant()
        Dim ServantAmount As Integer = 0

        For Each obj In Parent.Controls
            If TypeOf obj Is Servant Then
                ServantAmount += 1
            End If
        Next

        Return ServantAmount
    End Function

    Public Function CheckMoney(ByVal ProdPrice As Integer)
        Dim result As Boolean = False

        If (ProdPrice <= Parent.Controls.OfType(Of StatusPoints).ElementAtOrDefault(0).Money) Then
            result = True
        End If

        Return result
    End Function

    Private Sub Shop_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        Me.Cursor = Cursors.Arrow
    End Sub

    Private Sub FoodShop_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FoodShop1.MouseMove, FoodShop2.MouseMove, FoodShop3.MouseMove
        Me.Cursor = Cursors.Hand
    End Sub

    Private Sub ServantShop_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ServantShop.MouseMove
        Me.Cursor = Cursors.Hand
    End Sub

End Class